package com.fyyg.common.util.popular.util;

import com.fyyg.common.wechat.WeChatObject;
//import net.sf.json.JSONObject;
import com.alibaba.fastjson.JSONObject;

public class AccessToken {
	public  static String  APPID = WeChatObject.MCH_APPID;
	public  static String  SECRET = WeChatObject.MCH_APPSECRET;
	
    /** 
     * 获取jsticket 
     * @return 
     */  
    public static String getJsTicket(String token){  
			String result ="";
			String res ="";
            String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket";  
            String param ="access_token=" + token + "&type=jsapi";
			HttpRequest httpre = new HttpRequest();
			result = httpre.sendPost(url, param);
	    	JSONObject json = JSONObject.parseObject(result);
	    	res = json.getString("ticket");
            return res;  
    }  
	
    /** 
     * 获取AccessToken 
     * @return 
     */  
	public static String getAccessToken(){
		String result ="";
		String res ="";
		String url ="https://api.weixin.qq.com/cgi-bin/token";
		String param ="grant_type=client_credential&appid="+APPID+"&secret="+SECRET;
		System.out.println("-----------------------------------------------"+param);
		HttpRequest httpre = new HttpRequest();
		result = httpre.sendPost(url, param);
    	JSONObject json = JSONObject.parseObject(result);
		res = json.getString("access_token");
		return res;
	}
	
	
	
    public static void main(String[] args) {
    	AccessToken a = new AccessToken();
    	String token =a.getAccessToken();
    	System.out.println(token);
    	String ticket = getJsTicket(token);
    	System.out.println(ticket);
    }
}
